# -*- coding: utf-8 -*-
__author__ = 'chen'

import numpy as np
from sklearn import tree

class DicTreeDemo:
    # DicTreeDemo __init__()

    def __init__(self):
        file = open("./data/2.txt", "r")
        lines = file.readlines()
        data = []
        labels = []
        for line in lines:
            words = line.strip().split(",")
            data.append([w for w in words[:-1]])
            labels.append(words[-1])
        print(words)
        print(labels)
        self.X = np.array(data)
        y = np.array(labels)
        labels = np.zeros(shape=y.shape)
        print(labels)
        labels[y == ["fat"]] = 1
        print(labels)
        # data = np.loadtxt("./data/1.txt", dtype=np.str, delimiter=",")
        # print("data:")
        # print(data)
        # print("-"*40)
        # # 去掉最后一列
        # x_data = data[:, :-1]
        # # 只取最后一列
        # y_data = data[:, -1:]
        # print(x_data)
        # print("-" * 40)
        # print(y_data)
        # print("-" * 40)
        # labels = np.zeros(len(y_data))
        # for y in y_data:
        #     labels[y[0] == "fat"] = 1
        # print(labels)

    def transData(self):
        x_train, x_test, y_train,y_test = train_test_split(self.X,self.labels,test_size = 0.2)
        return x_train, x_test, y_train,y_test

d = DicTreeDemo()
